import 'package:changxindianzishangwu/pages/find/send_dynamic_page.dart';
import 'package:changxindianzishangwu/widget/icon_text_button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../util/colors.dart';

/**
 * 发布动态弹框
 * 2021-07-07
 * alex
 */

typedef OnCallBackListener =  Function();
class DynamicDialog {

  static BuildContext _context;
  static OnCallBackListener _onCallBackListener;

  static void showDialog(
      BuildContext context, OnCallBackListener onCallBackListener) {
    _context = context;
    _onCallBackListener = onCallBackListener;
    _openModalBottomSheet();
  }

  static Future _openModalBottomSheet() async {
    final option = await showModalBottomSheet(
        context: _context,
        builder: (BuildContext context) {
          return Container(
            color: Colors.white,
            height: height(214),
            alignment: Alignment.center,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                IconTextButton.icon(
                    onPressed: () {
                      Navigator.of(context).pop();

                      // Get.to(() => SendDynamicPage(
                      //       type: MediaType.MEDIA_TEXT_IMAGE,
                      //     )).then((value) {
                      //
                      //   if (value!=null) {
                      //     if (_onCallBackListener != null)
                      //       _onCallBackListener();
                      //   }
                      // });

                      _intentDynamicPage(MediaType.MEDIA_TEXT_IMAGE);

                    },
                    elevation: 0,
                    icon: Image.asset("assets/图片.png"),
                    label: Text(
                      "图片",
                      style: TextStyle(fontSize: sp(12)),
                    ),
                    iconTextAlignment: IconTextAlignment.iconTopTextBottom),
                IconTextButton.icon(
                    onPressed: () {
                      Navigator.of(context).pop();

                      _intentDynamicPage(MediaType.MEDIA_TEXT_VIDEO);

                    },
                    elevation: 0,
                    icon: Image.asset("assets/视频.png"),
                    label: Text(
                      "视频",
                      style: TextStyle(fontSize: sp(12)),
                    ),
                    iconTextAlignment: IconTextAlignment.iconTopTextBottom),
                // IconTextButton.icon(
                //     onPressed: () {
                //       Navigator.of(context).pop();
                //                      _intentDynamicPage(MediaType.MEDIA_TEXT_VOICE);
                //       // Navigator.push(context,
                //       //     MaterialPageRoute(builder: (BuildContext context) {
                //       //   return SendDynamicPage(
                //       //     type: MediaType.MEDIA_TEXT_VOICE,
                //       //   );
                //       // }));
                //     },
                //     elevation: 0,
                //     icon: Image.asset("assets/video.png"),
                //     label: Text(
                //       "语音",
                //       style: TextStyle(fontSize: sp(12)),
                //     ),
                //     iconTextAlignment: IconTextAlignment.iconTopTextBottom),
              ],
            ),
          );
        });

    print(option);
  }

  static void _intentDynamicPage(int media_text) async{
   bool value =await  Get.to(() => SendDynamicPage(
      type:media_text,
    ));
   if (value) {
     if (_onCallBackListener != null)
       _onCallBackListener();
   }
  }
}
